package Document;

import java.sql.*;
import java.util.ArrayList;

import javax.servlet.http.HttpSession;

public class Template {
	
	private int id;
	private String libelle;
	private String description;
	private String html;
	private String css;
	private String type;
	
	private ArrayList<Template> templates=new ArrayList<Template>();
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String getLibelle() {
		return libelle;
	}
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getHtml() {
		return html;
	}
	public void setHtml(String html) {
		this.html = html;
	}
	public String getCss() {
		return css;
	}
	public void setCss(String css) {
		this.css = css;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	public ArrayList<Template> listeTemplate(DAO connecteur, String Type) throws ClassNotFoundException, SQLException {
		Connection connexion=connecteur.getConnexion();
		String requete=	"SELECT ID_TEMPLATE, LB_TEMPLATE, DESC_TEMPLATE, CSS_TEMPLATE, TYPE_TEMPLATE"
		        + " FROM TEMPLATE"
				+ " WHERE TYPE_TEMPLATE = '?'";
		requete = requete.replace("?", Type);
		PreparedStatement statement=connexion.prepareStatement(requete);
		ResultSet resultat=statement.executeQuery();
		
		while (resultat.next())
		{
			 Template template=new Template();
			 template.setId(resultat.getInt("ID_TEMPLATE"));
			 template.setLibelle(resultat.getString("LB_TEMPLATE"));
			 template.setDescription(resultat.getString("DESC_TEMPLATE"));
			 template.setCss(resultat.getString("CSS_TEMPLATE"));
			 template.setType(resultat.getString("TYPE_TEMPLATE"));
			 this.templates.add(template);
		}		
		return templates;
	
	}
	
	public ArrayList<Template> listeHtmlTemplate(DAO connecteur, String Template) throws ClassNotFoundException, SQLException {
		Connection connexion=connecteur.getConnexion();
		String requete=	"SELECT ID_TEMPLATE, CSS_TEMPLATE"
		        + " FROM TEMPLATE"
				+ " WHERE ID_TEMPLATE = '?'";
		requete = requete.replace("?", Template);
		PreparedStatement statement=connexion.prepareStatement(requete);
		ResultSet resultat=statement.executeQuery();
		
		while (resultat.next())
		{
			 Template template=new Template();
			 template.setId(resultat.getInt("ID_TEMPLATE"));
			 template.setCss(resultat.getString("CSS_TEMPLATE"));
			 this.templates.add(template);
		}		
		return templates;
	
	}
	
	
}
